package apiday02.object;


public class ToStringDemo {
	public static void main(String[] args) {
		/*
		 * toString方法
		 * Foo默认继承于Object，继承了Object提供的
		 * toString() 方法.
		 */
		Foo foo = new Foo();
		String str = foo.toString();
		/*
		 * 默认的toString结果没有意义！类名@散列值
		 */
		System.out.println(str);

		Point p1 = new Point(3,5);
		System.out.println(p1.x + "," + p1.y);
		System.out.println(p1.toString());
		//Java的println方法会自动调用toString
		//这样就可以非常方便的输出对象的信息了
		System.out.println(p1);

		Point p2 = new Point(40,29);
		System.out.println(p2);

		Bullet bullet = new Bullet(30, 67, 20, 20);
		System.out.println(bullet);
	}
}
class Foo{
}
class Bullet extends Point{
	int w;
	int h;

	public Bullet(int x, int y, int w, int h) {
		super(x, y);
		this.w = w;
		this.h = h;
	}

	@Override
	public String toString() {
		return "Bullet [w=" + w + ", h=" + h + ", x=" + x + ", y=" + y + "]";
	}
}

/**
 * 一个坐标点
 */
class Point{
	int x;
	int y;
	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
	@Override
	public String toString() {
		return "Point [x=" + x + ", y=" + y + "]";
	}

}




